home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / gfx / show / jpegAGAsrc21.lha / jpegAGAsrc / ppm2AGA / pbmplus.h < prev    next >
C/C++ Source or Header  |  1994-04-18  |  8KB  |  261 lines

  1. /* pbmplus.h - header file for PBM, PGM, PPM, and PNM
  2. **
  3. ** Copyright (C) 1988, 1989, 1991 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #ifndef _PBMPLUS_H_
  14. #define _PBMPLUS_H_
  15.  
  16. #ifndef AZTEC_C
  17. #include <sys/types.h>
  18. #endif
  19. #include <ctype.h>
  20. #include <stdio.h>
  21. #ifdef VMS
  22. #include <perror.h>
  23. #include <errno.h>
  24. #endif
  25.  
  26. #if defined(USG) || defined(SVR4) || defined(VMS)
  27. #ifndef SYSV
  28. #define SYSV
  29. #endif
  30. #endif
  31. #if ! ( defined(BSD) || defined(SYSV) || defined(MSDOS) || defined(AMIGA) )
  32. /* CONFIGURE: If your system is >= 4.2BSD, set the BSD option; if you're a
  33. ** System V site, set the SYSV option; if you're IBM-compatible, set MSDOS;
  34. ** and if you run on an Amiga, set AMIGA. If your compiler is ANSI C, you're
  35. ** probably better off setting SYSV - all it affects is string handling.
  36. */
  37. #define BSD
  38. /* #define SYSV */
  39. /* #define MSDOS */
  40. /* #define AMIGA */
  41. #endif
  42.  
  43. /* CONFIGURE: If you have an X11-style rgb color names file, define its
  44. ** path here.  This is used by PPM to parse color names into rgb values.
  45. ** If you don't have such a file, comment this out and use the alternative
  46. ** hex and decimal forms to specify colors (see ppm/pgmtoppm.1 for details).
  47. #define RGB_DB "/usr/lib/X11/rgb"
  48. /*#define RGB_DB "/usr/openwin/lib/rgb.txt"*/
  49. #ifdef VMS
  50. #define RGB_DB ""
  51. #endif
  52.  
  53. /* CONFIGURE: If you want to enable writing "raw" files, set this option.
  54. ** "Raw" files are smaller, and much faster to read and write, but you
  55. ** must have a filesystem that allows all 256 ASCII characters to be read
  56. ** and written.  You will no longer be able to mail P?M files without 
  57. ** using uuencode or the equivalent, or running the files through pnmnoraw.
  58. ** Note that reading "raw" files works whether writing is enabled or not.
  59. */
  60. #define PBMPLUS_RAWBITS
  61.  
  62. /* CONFIGURE: PGM can store gray values as either bytes or shorts.  For most
  63. ** applications, bytes will be big enough, and the memory savings can be
  64. ** substantial.  However, if you need more than 8 bits of grayscale resolution,
  65. ** then define this symbol. Unless your computer is very slow or you are short
  66. ** of memory, there is no reason why you should not set this symbol.
  67. */
  68. /* #define PGM_BIGGRAYS */
  69.  
  70. /* CONFIGURE: Normally, PPM handles a pixel as a struct of three grays.
  71. ** If grays are stored in bytes, that's 24 bits per color pixel; if
  72. ** grays are stored as shorts, that's 48 bits per color pixel.  PPM
  73. ** can also be configured to pack the three grays into a single longword,
  74. ** 10 bits each, 30 bits per pixel.
  75. **
  76. ** If you have configured PGM with the PGM_BIGGRAYS option, AND you don't
  77. ** need more than 10 bits for each color component, AND you care more about
  78. ** memory use than speed, then this option might be a win.  Under these
  79. ** circumstances it will make some of the programs use 1.5 times less space,
  80. ** but all of the programs will run about 1.4 times slower.
  81. **
  82. ** If you are not using PGM_BIGGRAYS, then this option is useless -- it
  83. ** doesn't save any space, but it still slows things down.
  84. */
  85. /* #define PPM_PACKCOLORS */
  86.  
  87. /* CONFIGURE: uncomment this to enable debugging checks. */
  88. /* #define DEBUG */
  89.  
  90.  
  91. #if ( defined(SYSV) || defined(AMIGA) )
  92.  
  93. #include <string.h>
  94. #define index(s,c) strchr(s,c)
  95. #define rindex(s,c) strrchr(s,c)
  96. #define srandom(s) srand(s)
  97. #ifndef __GNUC__
  98. #define random rand
  99. #endif
  100. #ifndef _DCC    /* Amiga DICE Compiler */
  101. #define bzero(dst,len) memset(dst,0,len)
  102. #define bcopy(src,dst,len) memcpy(dst,src,len)
  103. #define bcmp memcmp
  104. extern void srand();
  105. extern int rand();
  106. #endif /* _DCC */
  107.  
  108. #else /* SYSV or AMIGA */
  109.  
  110. #include <strings.h>
  111. extern void srandom();
  112. extern long random();
  113.  
  114. #endif /*SYSV or AMIGA*/
  115.  
  116. #ifdef AMIGA
  117. #include <fcntl.h>
  118. #include <time.h>
  119. #include <stdlib.h>
  120. #else
  121. extern int atoi();
  122. extern void exit();
  123. extern long time();
  124. extern int write();
  125. #endif
  126.  
  127. /* CONFIGURE: On some systems, malloc.h doesn't declare these, so we have
  128. ** to do it.  On other systems, for example HP/UX, it declares them
  129. ** incompatibly.  And some systems, for example Dynix, don't have a
  130. ** malloc.h at all.  A sad situation.  If you have compilation problems
  131. ** that point here, feel free to tweak or remove these declarations.
  132. */
  133. #ifndef MCH_AMIGA
  134. #ifndef VMS
  135. #include <malloc.h>
  136. #endif
  137. #endif
  138. /* extern char* malloc(); */
  139. /* extern char* realloc(); */
  140. /* extern char* calloc(); */
  141.  
  142. /* CONFIGURE: Some systems don't have vfprintf(), which we need for the
  143. ** error-reporting routines.  If you compile and get a link error about
  144. ** this routine, uncomment the first define, which gives you a vfprintf
  145. ** that uses the theoretically non-portable but fairly common routine
  146. ** _doprnt().  If you then get a link error about _doprnt, or
  147. ** message-printing doesn't look like it's working, try the second
  148. ** define instead.
  149. */
  150. /* #define NEED_VFPRINTF1 */
  151. /* #define NEED_VFPRINTF2 */
  152.  
  153. /* CONFIGURE: If you don't want a fixed path to a X11 color name file
  154. ** compiled into PBMPlus, set this option.  Now RGB_DB (see Makefile)
  155. ** defines the name of an environment-variable that holds the complete
  156. ** path and name of this file.
  157. */
  158. /* #define A_RGBENV */
  159. /* CONFIGURE: On some smaller systems it's not a good idea to put large
  160. ** arrays on the stack.  With this option all large arrays are moved off
  161. ** the stack into globals.
  162. */
  163. #define A_SMALLSTACK
  164. /* CONFIGURE: Set this option if your compiler uses strerror(errno)
  165. ** instead of sys_errlist[errno] for error messages.
  166. */
  167. #define A_STRERROR
  168. /* CONFIGURE: On small systems without VM it is possible that there is
  169. ** enough memory for a large array, but it is fragmented.  So the usual
  170. ** malloc( all-in-one-big-chunk ) fails.  With this option, if the first
  171. ** method fails, pm_allocarray() tries to allocate the array row by row.
  172. */
  173. #define A_FRAGARRAY
  174.  
  175. /*
  176. ** Some special things for the Amiga.
  177. */
  178.  
  179. #ifdef AMIGA
  180. #include <clib/exec_protos.h>
  181. #define getpid(x)   ((long)FindTask(NULL))
  182. #ifdef _DCC /* Amiga DICE Compiler, dynamic stack variables */
  183. long _stack_fudge = 16384;
  184. long _stack_chunk = 32768;
  185. #endif /* _DCC */
  186. #endif /* AMIGA */
  187. /* End of configurable definitions. */
  188.  
  189.  
  190. #undef max
  191. #define max(a,b) ((a) > (b) ? (a) : (b))
  192. #undef min
  193. #define min(a,b) ((a) < (b) ? (a) : (b))
  194. #undef abs
  195. #define abs(a) ((a) >= 0 ? (a) : -(a))
  196. #undef odd
  197. #define odd(n) ((n) & 1)
  198.  
  199.  
  200. /* Definitions to make PBMPLUS work with either ANSI C or C Classic. */
  201.  
  202. #if __STDC__
  203. #define ARGS(alist) alist
  204. #else /*__STDC__*/
  205. #define ARGS(alist) ()
  206. #define const
  207. #endif /*__STDC__*/
  208.  
  209.  
  210. /* Initialization. */
  211.  
  212. void pm_init ( int* argcP, char* argv[] );
  213.  
  214. /* Variable-sized arrays definitions. */
  215.  
  216. char** pm_allocarray ( int cols, int rows, int size );
  217. char* pm_allocrow( int cols, int size );
  218. void pm_freearray( char** its, int rows );
  219. void pm_freerow( char* itrow );
  220.  
  221.  
  222. /* Case-insensitive keyword matcher. */
  223.  
  224. int pm_keymatch( char* str, char* keyword, int minchars );
  225.  
  226.  
  227. /* Log base two hacks. */
  228.  
  229. int pm_maxvaltobits( int maxval );
  230. int pm_bitstomaxval( int bits );
  231.  
  232.  
  233. /* Error handling definitions. */
  234.  
  235. void pm_message ( char*, ... );
  236. void pm_error ( char*, ... );            /* doesn't return */
  237. void pm_perror( char* reason );            /* doesn't return */
  238. void pm_usage ( char* usage );            /* doesn't return */
  239.  
  240.  
  241. /* File open/close that handles "-" as stdin and checks errors. */
  242.  
  243. FILE* pm_openr ( char* name );
  244. FILE* pm_openw ( char* name );
  245. void pm_close ( FILE* f );
  246.  
  247.  
  248. /* Endian I/O. */
  249.  
  250. int pm_readbigshort ( FILE* in, short* sP );
  251. int pm_writebigshort ( FILE* out, short s );
  252. int pm_readbiglong ( FILE* in, long* lP );
  253. int pm_writebiglong ( FILE* out, long l );
  254. int pm_readlittleshort ( FILE* in, short* sP );
  255. int pm_writelittleshort ( FILE* out, short s );
  256. int pm_readlittlelong ( FILE* in, long* lP );
  257. int pm_writelittlelong ( FILE* out, long l );
  258.  
  259.  
  260. #endif /*_PBMPLUS_H_*/
  261.